<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2019/5/24
  Time: 16:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap.css"
          media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/kkpagerOrange.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/personal.css" media="all">
    <script src="${pageContext.request.contextPath}/js/jquery2.js"></script>
    <script src="${pageContext.request.contextPath}/js/kkpager.min.js"></script>
</head>
<body>
<div class="container-fluid">
    <table class="table  table-hover table-condensed">
        <thead>
        <tr>
            <th>部门主键</th>
            <th>部门编号</th>
            <th>部门名称</th>
            <th>上级部门</th>
            <th>部门负责人</th>
            <th>部门电话</th>
            <th>部门传真</th>
            <th>部门邮箱</th>
            <th>部门职责</th>
            <th>跳转</th>
        </tr>
        </thead>
        <tbody id="tbody" class="table table-striped">

        </tbody>
    </table>
    <button class="btn btn-info" id="referrerBtn" onclick="window.location.href=document.referrer">返回</button>
</div>
<div style="width:800px;margin:0 auto;">
    <div id="kkpager"></div>
</div>
<script type="text/javascript">
    function getParameter(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    //init
    $(function () {
        var totalPage = 200;
        var totalRecords = 2;
        var pageNo = getParameter('pno');
        if (!pageNo) {
            pageNo = 1;
        }
        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno: pageNo,
            //总页码
            total: totalPage,
            //总数据条数
            totalRecords: totalRecords,
            mode: 'click',//默认值是link，可选link或者click
            click: function (n) {
                this.selectPage(n);
                return false;
            }
            , lang: {
                firstPageText: '首页',
                firstPageTipText: '首页',
                lastPageText: '尾页',
                lastPageTipText: '尾页',
                prePageText: '上一页',
                prePageTipText: '上一页',
                nextPageText: '下一页',
                nextPageTipText: '下一页',
                totalPageBeforeText: '共',
                totalPageAfterText: '页',
                currPageBeforeText: '当前第',
                currPageAfterText: '页',
                totalInfoSplitStr: '/',
                totalRecordsBeforeText: '共',
                totalRecordsAfterText: '条数据',
                gopageBeforeText: '&nbsp;转到',
                gopageButtonOkText: '确定',
                gopageAfterText: '页',
                buttonTipBeforeText: '第',
                buttonTipAfterText: '页'
            }
        });

    });
</script>


<script src="js/tao.js"></script>
</body>
<script>
    /**
     * document.referrer获取前一个url
     */
    /**
     * 需要修改文件把maven_project去掉
     */
    if ("http://localhost:8080/maven_project/" == document.referrer ||
        document.referrer == "http://localhost:8080/maven_project/showDeptData.jsp") {
        var elementById = document.getElementById("referrerBtn");
        elementById.innerText = "刷新";
        elementById.onclick = function () {
            window.location.reload();
        }
    }
    $(function () {
        $.ajax({
            type: "get",
            url: "dept/queryAll",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, da) {
                    if (index % 2 == 0) {
                        var rows = "<tr class='success'>" +
                            "<th>" + da.id + "</th>" +
                            "<th>" + da.dbian + "</th>" +
                            "<th>" + da.dname + "</th>" +
                            "<th>" + da.wname + "</th>" +
                            "<th>" + da.dmanager + "</th>" +
                            "<th>" + da.dtel + "</th>" +
                            "<th>" + da.dfax + "</th>" +
                            "<th>" + da.demail + "</th>" +
                            "<th>" + da.duty + "</th>" +
                            "<th><a href='' class='btn btn-link'>reverse</a></th>" +
                            "</tr>"
                    } else {
                        var rows = "<tr class='danger'>" +
                            "<th>" + da.id + "</th>" +
                            "<th>" + da.dbian + "</th>" +
                            "<th>" + da.dname + "</th>" +
                            "<th>" + da.wname + "</th>" +
                            "<th>" + da.dmanager + "</th>" +
                            "<th>" + da.dtel + "</th>" +
                            "<th>" + da.dfax + "</th>" +
                            "<th>" + da.demail + "</th>" +
                            "<th>" + da.duty + "</th>" +
                            "<th><a href='' class='btn btn-link'>reverse</a></th>" +
                            "</tr>"
                    }
                    $("#tbody").append(rows);
                })
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });
    });
</script>
</html>
